package com.api.shopapi.mapper;

import com.api.shopapi.entity.ActivityContent;
import com.api.shopapi.entity.ActivityItem;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface ActivityContentMapper {

    @Insert("insert into activity_content " +
            "(" +
            "ActivityContentCode," +
            "ActivityTypeCode," +
            "ActivityItemCode," +
            "Name," +
            "Status," +
            "GovernmentCode," +
            "CommandCenterCode," +
            "Frequency" +
            ") " +
            "values " +
            "(" +
            "#{activityContent.ActivityContentCode}," +
            "#{activityContent.ActivityTypeCode}," +
            "#{activityContent.ActivityItemCode}," +
            "#{activityContent.Name}," +
            "#{activityContent.Status}," +
            "#{activityContent.GovernmentCode}," +
            "#{activityContent.CommandCenterCode}," +
            "#{activityContent.Frequency}" +
            ")" )
    int insert(@Param("activityContent") ActivityContent activityContent);


    @Delete("delete from activity_content where activityContentCode=#{activityContentCode}")
    int delete(@Param("activityContentCode") String activityContentCode);


    @Update("update activity_content set " +
            " Name=#{activityContent.Name}," +
            " Status=#{activityContent.Status}," +
            " ActivityTypeCode=#{activityContent.ActivityTypeCode}," +
            " ActivityItemCode=#{activityContent.ActivityItemCode}," +
            " Frequency=#{activityContent.Frequency}" +
            " where activityContentCode=#{activityContent.activityContentCode}")
    int update(@Param("activityContent") ActivityContent activityContent);


    @Select("select * from activity_content where activityContentCode=#{activityContentCode} limit 1")
    ActivityContent getByActivityContentCode(@Param("activityContentCode") String activityContentCode);


    @Select("select * from activity_content where activityItemCode=#{activityItemCode}")
    List<ActivityContent> ListByActivityItemCode(@Param("activityItemCode") String activityItemCode);



    @Select("<script>" +
            "select * from activity_content where commandCenterCode=#{commandCenterCode}" +

            "<if test =' activityTypeCode != \"\" '>" +
            " and activityTypeCode = #{activityTypeCode} " +
            "</if>" +
            "<if test =' activityItemCode != \"\" '>" +
            " and activityItemCode = #{activityItemCode} " +
            "</if>" +

            "</script>")
    List<ActivityContent> listByCommandCenterCode(@Param("commandCenterCode") String commandCenterCode,
                                               @Param("activityTypeCode") String activityTypeCode,
                                               @Param("activityItemCode") String activityItemCode);


}
